package com.innovation.chengzhangriji.ui.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.R;
import com.nostra13.universalimageloader.core.ImageLoader;

public class DTVideoHolder extends DTHolder {

    public interface OnClickVideoListener {

        void onClickVideo(DTVideoHolder holder);
    }

    private OnClickVideoListener onClickVideoListener;

    private ImageView imageThumbnail;

    public DTVideoHolder(View itemView) {
        super(itemView);

        View view = LayoutInflater.from(itemView.getContext()).inflate(R.layout.item_discover_video, getContent());
        imageThumbnail = (ImageView) view.findViewById(R.id.image_thumbnail);
        imageThumbnail.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (onClickVideoListener == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.image_thumbnail:
                onClickVideoListener.onClickVideo(this);
                break;
        }
    }

    public void setOnClickVideoListener(OnClickVideoListener onClickVideoListener) {
        this.onClickVideoListener = onClickVideoListener;
    }

    public void setVideoThumbnailUrl(String url) {
        if(TextUtils.isEmpty(url)) return;
        if(url.startsWith("/")) {
            ImageLoader.getInstance().displayImage("file://" +url, imageThumbnail, Config.getOptionsPhoto());
        } else {
            ImageLoader.getInstance().displayImage(url, imageThumbnail, Config.getOptionsPhoto());
        }
    }
}
